<template>
  <div class="app-container">

    <div class="filter-container">
      <el-date-picker
        v-model="listQuery.checktime"
        type="daterange"
        range-separator="至"
        class="filter-item"
        style="width:300px"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd"
      >
      </el-date-picker>

      <el-button-group class="filter-item">
        <el-button
          size="small"
          type="primary"
          icon="el-icon-search"
          @click="search"
        >
          搜索
        </el-button>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-refresh"
          @click="refresh"
        >
          重置
        </el-button>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-paperclip"
          @click="explortExcel"
        >
          导出
        </el-button>

      </el-button-group>

    </div>


    <el-table
      v-loading="listLoading"
      :data="rankData"
      id="table"
      element-loading-text="Loading"
      fit
      height="100%"
      border
      :header-row-class-name="Tableheader"
      class="table-container"
    >
      <el-table-column>
        <template slot="header" slot-scope="scope">
          <div style="font-weight: bold;font-size:20px;padding:5px 0;text-align:center;">{{ listQuery.checktime[0] }} - {{ listQuery.checktime[1] }}机构回复数据</div>
        </template>
        <el-table-column
          width="300"
          label="机构名"
          align="center"
        >
          <template slot-scope="scope">
            <div class="fontSize">{{ scope.row.user_name }}</div>
          </template>
        </el-table-column>

        <el-table-column
          label="数量"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            <div class="fontSize">{{ scope.row.count }}</div>
          </template>
        </el-table-column>
      </el-table-column>
    </el-table>

  </div>
</template>
<style>
.el-card__header {
  padding: 15px 20px;
}

.el-progress {
  margin-top: 5px;
  display: flex;
}

.progress-item {
  padding-top: 0 !important;
  padding-bottom: 30px;
}
</style>
<script>
import exportExecl from '@/utils/excel'
import { getRankJigouData } from '@/api/rank'

let id = 0
export default {
  data() {
    return {
      total: 0,
      list: [],
      drawer: true,
      rankData: [],
      countTypeData: [],
      listLoading: false,
      listQuery: {
        checktime: [new Date(new Date().getFullYear(), new Date().getMonth(), 1).toLocaleDateString('fr-CA'), new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0, 23, 59, 59).toLocaleDateString('fr-CA')],
        chart: 3
      },
      baseData: [],
      dialogVisible: false,
      dialogType: 'create',
      loading: false
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    search() {
      this.fetchData()
    },
    Tableheader({ row, rowIndex }) {
      if (rowIndex === 0) {
        return 'tableHeader'
      }
    },
    refresh() {
      this.listQuery = {
        chart: 3,
        checktime: ''
      }
    },
    explortExcel() {
      let fileName = (this.listQuery.checktime[0]) + '至' + (this.listQuery.checktime[1]) + '的机构回复数据'
      exportExecl('table', fileName + '.xlsx')
    },
    fetchData() {
      this.listLoading = true
      getRankJigouData(this.listQuery).then(response => {
        this.listLoading = false
        this.rankData = response.data
      })
    }
  }
}
</script>
